package controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author manchi520
 * @date 2022/7/2
 * @apiNote
 */
@Controller
@RequestMapping("/excel")
public class ExcelController {
    @RequestMapping("/read")
    @ResponseBody //向客户端返回json格式数据
    public List<Map<String, Object>> readExcel(HttpServletRequest req){
        //获取文件路径参数
        String path = req.getParameter("path");
        ExcelReader reader = ExcelUtil.getReader(path);
        //读取的数据用Map集合存取，key为Excel的标题，value为对应的单元格数据
        List<Map<String, Object>> maps = reader.readAll();
        return maps;
    }
}
